#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
/*
https://msdn.microsoft.com/en-us/library/hh270864.aspx
https://msdn.microsoft.com/en-us/library/hh598953.aspx
https://msdn.microsoft.com/en-us/library/hh419385.aspx
http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx

How to: Convert Between Various String Types
https://msdn.microsoft.com/en-us/library/ms235631.aspx

C++ Type System (Modern C++)
https://msdn.microsoft.com/en-us/library/hh279663.aspx

String and Character Literals (C++)
https://msdn.microsoft.com/en-us/library/69ze775t.aspx

Surrogates and Supplementary Characters
https://msdn.microsoft.com/library/dd374069(v=vs.85).aspx

Character Sets
https://msdn.microsoft.com/es-mx/library/dd317743(v=vs.85).aspx

Project and Solution Files
https://msdn.microsoft.com/en-us/library/hx0cxhaw.aspx
*/

namespace cppUnitTest1
{
	struct T
	{
		int n;
		char* ptr;
	};

	TEST_CLASS(UnitTest1)
	{
	public:

		TEST_METHOD(TestMethod4)
		{
			//Arrange
			T* t = new T;
			t->n = 123;
			t->ptr = nullptr;
			char* s1 = create_string("X");
			char* s2 = "Y";

			//Act
			change_text_to(&t->ptr, s1);
			change_text_to(&t->ptr, s2);

			//Assert
			Assert::AreEqual<std::string>(std::string(s2), std::string(t->ptr));

			delete[] s1;
		}

		TEST_METHOD(TestMethod3)
		{
			//Arrange
			T* t = new T;
			t->n = 123;
			t->ptr = nullptr;
			char* s1 = "X";
			char* s2 = "Y";

			//Act
			change_text_to(t, s1);
			change_text_to(t, s2);

			//Assert
			Assert::AreEqual<std::string>(std::string(s2), std::string(t->ptr));
		}

		char* create_string(char* chars)
		{
			return 0;
		}
		void change_text_to(T* x, char* s)
		{
			x->ptr = s;
		}
		void change_text_to(char** ptr, char* s)
		{
			*ptr = s;
		}

		TEST_METHOD(TestMethod2)
		{
			//Arrange
			T* t = new T;
			T* u = new T;

			//Act
			t->n = 123;
			t->ptr = nullptr;
			char* s = new char[1];
			s[0] = 'U';
			u->ptr = s;

			//Assert
			Assert::IsNotNull(t);
			Assert::AreEqual<int>(123, t->n);
			Assert::AreEqual(nullptr, t->ptr);
			Assert::AreEqual('U', u->ptr[0]);
			Assert::AreEqual('U', *u->ptr);

			delete t;
			delete u;
			delete[] s;
		}
	};
}